function getimgname(){
    let imginput=document.getElementById("inputimg");
    let filearr=imginput.files;
    let imgshow=document.getElementById("showimg");
    let s = `<img src="../img/tea-img/${filearr[0].name}">`;
    imgshow.innerHTML = s;
    return filearr[0].name;
}

function addTea(){
    let divobj= document.getElementById("box");
    let inputlist=divobj.getElementsByTagName("input");
    let teatype=document.getElementById("teaType").value;
    let teaname=inputlist[0].value;
    let teaprice=inputlist[2].value;
    let teadescribe=document.getElementById("describe").value;
    let teaimg=getimgname();

    let obj={
        teatype: teatype,
        teaname:teaname,
        teaprice:teaprice,
        teadescribe:teadescribe,
        teaimg:teaimg
    }
    $.ajax({
        type:"post",//请求方式   get  post
        url:"/js/teaAdd",//接口地址
        data:JSON.stringify(obj),//是否携带参数
        dataType:"json",//数据类型
        success:function(data){ //回调函数   data表示后台接口返回的数据
           if(data){
            alert("添加成功！");
            location.reload();
           }else{
            alert("该茶叶已存在,添加失败！");
            location.reload();
           }
        }

    }) 
}